﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_CartLayout.cshtml";
}
@model SALESolution.Models.ShoppingCartModels
<script src="~/Scripts/jquery-1.6.2.min.js"></script>
<script type="text/javascript">
    function RemoveFromCart(id) {
        if (confirm('Bạn thực sự muốn xóa sản phẩm này khỏi giỏ hàng?')) {
            $.post("/ShoppingCart/RemoveFromCart", { "id": id },
            function (data) {
                if (data.Code == '0') {
                    alert('Xóa sản phẩm khỏi giỏ hàng thành công');
                    window.location = '/ShoppingCart';
                }
            });
        }
        return false;
    }
    //$(document).ready(function () {
       
    //    var a = $.cookie("value");
    //    alert(a);
    //    $('#quantity_2 option[value="'+a+'"]').prop('selected', true);
        
    //});
    function UpdateQuantity(id, quantity) {
        //$.cookie("value", quantity);
     
        $.post("/ShoppingCart/UpdateQuantity", { "id": id, "quantity": quantity },
            function (data) {
                if (data.Code == '0') {
                    window.location = '/ShoppingCart';
                }
            });
        return false;
    }
</script>

<div class="container">

    <div class="sixteen columns" style="margin-left: 10px;">

        <div class="box_head">
            <h3>Thông tin giỏ hàng</h3>
        </div>
        <!--end box_head -->
        @if (Model != null && Model.Cart != null)
        {
            <table class="cart_table">
                <thead>
                    <tr>
                        <th class="first_td">
                            <h4>Tên sản phẩm</h4>
                        </th>
                        <th>
                            <h4>Số lượng</h4>
                        </th>
                        <th>
                            <h4>Giá tiền</h4>
                        </th>
                        <th>
                            <h4>Tổng tiền</h4>
                        </th>
                        <th>
                            <h4>Xóa</h4>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model.Cart.ListItem)
                    {
                        <tr>
                            <td class="first_td">
                                <div class="clearfix">
                                    <img src="@item.ProductImage" alt="product image">
                                    <span>
                                        <strong><a href="#">@item.ProductName</a></strong><br>
                                        <ul>
                                            <li><a href="javascript:void(0);">text</a></li>
                                            <li><a href="javascript:void(0);">text</a></li>
                                            <li><a href="javascript:void(0);">text</a></li>
                                            <li><a href="javascript:void(0);">text</a></li>
                                            <li><a href="javascript:void(0);">text</a></li>
                                        </ul>

                                    </span>
                                </div>
                            </td>
                            <td class="quantity">
                               
                                    @*<label>
                                        <input class="gray_btn" type="button" id="min_qty" class="qty" value="-">
                                    </label>*@
                                    @* <label>
                                        <input type="text" class="value_default" maxlength="12" name="" id="" class="" value="2" size="2">
                                    </label>*@
                                    <select id="quantity_@item.ProductID" title="Số lượng" style="top:0px; display:block;visibility:inherit;" name="thanh toan" class="" onchange="return UpdateQuantity(@item.ProductID,this.value);">
                                        <option value="1">1</option>
                                        <option value="2">2</option>
                                        <option value="3">3</option>
                                        <option value="4">4</option>
                                        <option value="5">5</option>
                                        <option value="6">6</option>
                                        <option value="7">7</option>
                                        <option value="8">8</option>
                                        <option value="9">9</option>
                                        <option value="10">10</option>
                                    </select>
                                    @* <label>
                                        <input class="gray_btn" type="button" id="max_qty" class="qty" value="+">
                                    </label>*@
                                    <script type="text/javascript">
                                       
                                        $('#quantity_@item.ProductID option[value="' + @item.Quantity + '"]').prop('selected', true);
                                    </script>
                                
                                
                            </td>
                            <td>
                                <h5>@item.Price.ToString("N0") VNĐ</h5>
                            </td>
                            <td class="total_price">
                                @if (Model != null && @Model.Cart != null)
                                { 
                   
                                    <h5>@item.Total.ToString("N0") VNĐ
                                    </h5>
                                }

                            </td>
                            <td>
                                <a class="delete_item" href="#" onclick="return RemoveFromCart(@item.ProductID);">delete</a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            <!--end cart_table-->
        }
    </div>
    <!--end sixteen-->

</div>
